<?php

class WeixinFace extends FaceBase
{
	private $nohf = array();

	public function __construct()
	{
		parent::__construct();
		if(!in_array(N_ACTION,$this->nohf)){
			n_mod('skin')->header();
		}
		$this->mysql = n_api('mysql')->cname('weixin');
		$this->api = n_api('weixin');
	}

	public function detail()
	{
		$param = $this->param('wxid:char:empty');
		$wxid = $param['wxid'];
		$mprank = n_api("mprank");
		$article = n_api('article');

		$rs['wxDetail'] = $this->api->getWxDetail($wxid);
		//$data['wxRankByDay'] = $mprank->getRankByDay($wxid);
		//$data['wxRankByWeek'] = $mprank->getRankByWeek($wxid);
		$wxIndexWeek = $mprank->getWxIndexByWeek($wxid);
		//$rs['wxArticleWeek'] = $article->getHotArticleWeek($compete1);
		$rs['wxList'] = $article->getNewArticleByWxid($wxid);

		foreach($wxIndexWeek as $key=>$val){
			$rs['compete1']['weixin_index'][$key] = $val['weixin_index'];
			$rs['compete1']['all_read_num'][$key] = $val['all_read_num'];
			$rs['compete1']['all_like_num'][$key] = $val['all_like_num'];
			$rs['compete1']['head_read_num'][$key] = $val['head_read_num'];
			$rs['compete1']['average_read_num'][$key] = $val['average_read_num'];
			$rs['compete1']['max_read_num'][$key] = $val['max_read_num'];
			$rs['compete1']['pub_num'][$key] = $val['pub_num'];
		}
		if (isset($_SESSION['ppid'])){
			$data['cart'] = n_api('cart')->getCartByPpid($_SESSION['ppid']);
		}
		$this->_html('detail', $rs);
	}

	public function compete()
	{
		$param = $this->param('
			compete1:char:ignore,
			compete2:char:ignore
		');

		$mprank = n_api("mprank");
		$article = n_api('article');

		$compete1 = isset($param['compete1']) ? $param['compete1'] : 'zsnc-ok';
		$compete2 = isset($param['compete2']) ? $param['compete2'] : 'zhanhao668';
	
		$rs['wxDetail1'] = $this->api->getWxDetail($compete1);
		//$rs['wxRankByDay'] = $mprank->getRankByDay($compete1);
		//$rs['wxRankByWeek'] = $mprank->getRankByWeek($compete1);
		$wxIndexWeek = $mprank->getWxIndexByWeek($compete1);
		//$rs['wxArticleWeek'] = $article->getHotArticleWeek($compete1);
		foreach($wxIndexWeek as $key=>$val){
			$rs['compete1']['weixin_index'][$key] = $val['weixin_index'];
			$rs['compete1']['all_read_num'][$key] = $val['all_read_num'];
			$rs['compete1']['all_like_num'][$key] = $val['all_like_num'];
			$rs['compete1']['head_read_num'][$key] = $val['head_read_num'];
			$rs['compete1']['average_read_num'][$key] = $val['average_read_num'];
			$rs['compete1']['max_read_num'][$key] = $val['max_read_num'];
			$rs['compete1']['pub_num'][$key] = $val['pub_num'];
		}

		$rs['wxDetail2'] = $this->api->getWxDetail($compete2);
		//$rs['wxRankByDay'] = $mprank->getRankByDay($compete2);
		//$rs['wxRankByWeek'] = $mprank->getRankByWeek($compete2);
		$wxIndexWeek = $mprank->getWxIndexByWeek($compete2);
		//$rs['wxArticleWeek'] = $article->getHotArticleWeek($compete2);
		foreach($wxIndexWeek as $key=>$val){
			$rs['compete2']['weixin_index'][$key] = $val['weixin_index'];
			$rs['compete2']['all_read_num'][$key] = $val['all_read_num'];
			$rs['compete2']['all_like_num'][$key] = $val['all_like_num'];
			$rs['compete2']['head_read_num'][$key] = $val['head_read_num'];
			$rs['compete2']['average_read_num'][$key] = $val['average_read_num'];
			$rs['compete2']['max_read_num'][$key] = $val['max_read_num'];
			$rs['compete2']['pub_num'][$key] = $val['pub_num'];
		}

		if (isset($_SESSION['ppid'])){
			$data['cart'] = n_api('cart')->getCartByPpid($_SESSION['ppid']);
		}
		$this->_html('compete', $rs);
	}


	
	public function __destruct(){
		if(!in_array(N_ACTION,$this->nohf)){
			n_mod('skin')->footer();
		}
	}


}